package com.sdx.console.crm.service;

import com.ibeetl.admin.core.util.DateUtil;
import com.sdx.console.crm.entity.CrmMessage;
import com.sdx.console.crm.entity.CrmSession;
import org.beetl.sql.core.SQLManager;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @ClassName CrmMessageService
 * @Description: 消息服务
 * @author: tanbaocai
 * @date: 2019/7/24 15:38
 */
@Service
public class CrmMessageService {

	@Resource
	private SQLManager sqlManager;

	public void insert(CrmSession crmSession,String msg){
		CrmMessage crmMessage = new CrmMessage();
		crmMessage.setAppId(crmSession.getAppId());
		crmMessage.setCustomerId(crmSession.getCustomerId());
		crmMessage.setOpenid(crmSession.getOpenId());
		crmMessage.setSourceType(crmSession.getSourceType());
		crmMessage.setMsgClass(2);
		crmMessage.setMsgType("text");
		crmMessage.setSafeContent(msg);
		crmMessage.setUserId(crmSession.getUserId());
		crmMessage.setCreateTime(new Date());
		crmMessage.setCreateDay(DateUtil.now());
		sqlManager.insert(CrmMessage.class,crmMessage);
	}

}
